package com.example.lianxirenlist;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdaper extends RecyclerView.Adapter<MyAdaper.Holder> {
    private List<DataBean> data;
    private Context context;

    public MyAdaper(Context context) {
        this.context = context;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    @NonNull

    @Override
    public Holder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(context).inflate(R.layout.list_item_list,null));
    }

    @Override
    public void onBindViewHolder(@NonNull  MyAdaper.Holder holder, int position) {
        holder.text.setText(data.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context,ListXiang.class);
                String id=data.get(position).getId();
                intent.putExtra("id",id);
                context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return null!=data?data.size():0;
    }

    class Holder extends RecyclerView.ViewHolder{

        TextView text;

        public Holder(@NonNull  View itemView) {
            super(itemView);

            text=itemView.findViewById(R.id.text_user);
        }
    }
}
